package com.jiawei.service.impl;

import com.jiawei.entity.database.User;
import com.jiawei.entity.pojo.Rt;
import com.jiawei.mapper.MenuMapper;
import com.jiawei.mapper.UserMapper;
import com.jiawei.service.MenuService;
import com.jiawei.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author : willian fu
 * @date : 2019/12/21
 */
@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private JwtUtil jwtUtil;

    @Autowired
    private MenuMapper menuMapper;

    /**
     * 查询用户所有可见菜单
     *
     * @return
     */
    @Override
    public Object getMenus() {
        User user = jwtUtil.jwtGetUser();
        return null == user ?
                Rt.badRequest("token 解析失败")
                :Rt.ok(menuMapper.getMenusByUser(user.getId()));
    }
}
